package com.czhi.multi;

import com.lmax.disruptor.WorkHandler;

import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;

public class Consumer implements WorkHandler<Order> {
    private String consumerId;
    private AtomicLong count;
    private ThreadLocalRandom random = ThreadLocalRandom.current();

    public Consumer(String s) {
        this.consumerId = s;
    }

    @Override
    public void onEvent(Order event) throws Exception {
        Thread.sleep(1 * random.nextInt(5));
        System.out.println("当前消费者: " + this.consumerId + ", 消费信息ID: " + event.getId());
        count.getAndIncrement();
    }

    public long getCount() {
        return count.get();
    }
}
